from django.shortcuts import render
from django.core.mail import send_mail
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse, JsonResponse

# Create your views here.


@csrf_exempt
def send_mail_post(request):
    from_mail = getattr(settings, "FROM_MAIL", None)
    to_mail = getattr(settings, "TO_MAIL", None)
    try:
        send_mail(
            '反馈意见',
            '反馈人：{}\n\n反馈人邮箱：{}\n\n反馈内容：\n{}'.format(request.POST.get('title', ''),request.POST.get('to_mail', ''),request.POST.get('content', '')),
            from_mail,
            [to_mail] 
        )
    except Exception as e:
        return JsonResponse({'status': 500, 'data': None})
    return JsonResponse({'status': 200, 'data': None})
